/**
 * Created by yu on 16/8/24.
 * 异步动态时钟
 */

var fs = require('fs');
var http = require('http');

var server = http.createServer(function(req,res){
    var url = req.url;
    //           此处必须是数字200


    if(url=='/'){
        res.writeHead(200,{'Content-Type':'text/html;charset=utf-8'});
        fs.readFile('./clock.html','utf-8',function(err,data){
            res.end(data);
        })
    }else if(url=='/clock'){
        res.end(new Date().toLocaleString());
        //res.statusCode = 404;//设置状态码,404页面没找到
        //res.end();
    }

});
server.listen('8080','localhost');
